package DataStructures.sort;

import java.util.Arrays;

/**
 * @author ：ALi
 * @date ：Created in 2021/11/9 21:27
 * @description：希尔排序---插入法
 * @modified By：
 * @version: $
 */
public class ShellSort2 {
    public static void main(String[] args) {
        int[] array = {12, 8, 9, 1, 7, 2, 3, 5, 4, 6, 0, 10};
        ShellSortArray(array);
        System.out.println(Arrays.toString(array));

    }

    public static void ShellSortArray(int[] array) {


        for (int gap = array.length / 2; gap > 0; gap = gap / 2) {
            for (int i = gap; i < array.length; i++) {
                int j = i;
                int temp = array[j];
                if (array[j] < array[j - gap]) {
                    while (j - gap >= 0 && temp < array[j - gap]) {

                        array[j] = array[j - gap];
                        j = j - gap;
                    }
                    array[j] = temp;
                }

            }
        }
    }
}